# coding=utf-8
'''
Created on 2013-12-26

@author: sunxiang
'''
from mongoengine import *
from model.meta import MetaData

import simplejson

class MetaService(object):

    def get_current_user_count(self):
        metadatas = MetaData.objects
        if(metadatas):
            metadata = simplejson.loads(metadatas[0].to_json())
            return metadata['usercount']
        return 0
    
    def set_current_user_count(self, count):
        metadatas = MetaData.objects
        if(metadatas):
            metadata = metadatas[0]
            metadata.usercount = count
            metadata.save()
        else:
            metadata = MetaData(usercount = 1)
            
        metadata.save()   